var loader = {
    init: function(){

    },
    loadImage: function(url){
        var img = new Image();
        img.src = url;
        if (!img.complete){
            var that = this;
            img.onload = function(){
                that._onItemLoaded(img);
            }
            img.onerror = function(){
                that.onError(img);
            }
            ++this.left;
        }
        return img;
    },
    loadAudio: function(url){
        var audio = new Audio();
        var that = this;
        audio.src = url;
        audio.addEventListener("canplaythrough", function(){
            that._onItemLoaded(audio);
        }, false);
        ++this.left;
        return audio;
    },
    left: 0,
    _onItemLoaded: function(item){
        --this.left;
        if (this.left == 0){
            if (this.onAllLoaded){
                this.onAllLoaded();
            }
        } else {
            if (this.onItemLoaded){
                this.onItemLoaded();
            }
        }
    },
    //callbacks for external usage
    onAllLoaded: null,
    onItemLoaded: null,
    onError: null
};